package Q1;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] arr = new int[n];
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
            stringBuilder.append(arr[i]);
        }

        int q = scanner.nextInt();
        while (q > 0) {
            q--;
            int x = scanner.nextInt();
            String temp = stringBuilder.substring(0, x);
            char[] ch = temp.toCharArray();
            Arrays.sort(ch);
            System.out.println(ch[ch.length - 2]);
        }
    }
}
